package com.jydd.liaomingframe.loading;

import com.jydd.liaomingframe.R;
import com.lm.liaoming.base.custom.CustomBaseActivity;
import com.lm.liaoming.tool.StatesUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

public class LoadingActivity extends CustomBaseActivity {
    private List<Fragment> list=new ArrayList<>();

    @BindView(R.id.loading_mVp)
    ViewPager mVp;
    private LoadingAdapter adapter;


    @Override
    public int setLayoutId() {
        StatesUtils.setStatusBar(this);
        return R.layout.activivty_loading;
    }

    @Override
    public void initVariables() {
    }

    @Override
    public void initViews() {
        ButterKnife.bind(this);
        list.clear();
        for (int i = 0; i < 4; i++) {
            list.add(LoadingFragment.newInstance(i));
        }
        adapter = new LoadingAdapter(getSupportFragmentManager());
        mVp.setAdapter(adapter);
        adapter.addData(list);
    }

   class LoadingAdapter extends FragmentPagerAdapter {
        List<Fragment> list;
       public LoadingAdapter(FragmentManager fm) {
           super(fm);
           this.list=new ArrayList<>();
       }

       @Override
       public Fragment getItem(int position) {
           return list.get(position);
       }

       @Override
       public int getCount() {
           return list.size();
       }

       public void addData(List<Fragment> list){
           this.list.addAll(list);
           notifyDataSetChanged();
       }
   }
}
